<template>
  <div
    :id="id"
    style="width:50%;height:400px;border: 1px dashed gray"
  >
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
    props:{
        id:{
            type:String,
            require:true
        },
        data:{
            type:Array,
            required:true
        }
    },
  mounted() {
    var chartDom = document.getElementById(this.id)
    var myChart = echarts.init(chartDom)
    var option

    option = {
        title:{
            text:'性别分布情况',
            x:'center'
        },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        left: 'center'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2,
            normal:{
                color:function(colors){
                    var colorList = ['skyblue','#f491b4']
                    return colorList[colors.dataIndex]
                }
            }
          },
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: '40',
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data:this.data
        }
      ]
    }

    option && myChart.setOption(option)
  }
}
</script>

<style lang="scss" scoped>
</style>